package com.h.book.config;

import com.h.book.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

@Configuration
// 注册配置拦截器
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;
    private List<String> excludePath = Arrays.asList(
            "/user/login",
            "/**/*.css",
            "/**/*.js",
            "/**/*.html",
            "/**/*.png"
            );

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**") // 设置拦截器的拦截路径 ，/** 是所有路径 但是不是所有的路径都需要进行拦截的所以需要去除一些
                .excludePathPatterns(excludePath);
    }
}
